import 'package:enterprise_v6_app/app/components/special_operation/custom_file_upload_page.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_multi_signature_page.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_picker_video.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/data/entities/application/execute_entity.dart';

///特殊作业-安全交底组件
///[ticketDisclose] 安全交底数据
///[isEnabled] 是否可编辑
///[isChange] 是否在交接班中
class CustomSafetyDisclosurePage extends StatefulWidget {
  const CustomSafetyDisclosurePage({
    required this.ticketDisclose,
    super.key,
    this.isEnabled = true,
    this.isChange = false,
  });

  final ExecuteTicketDiscloseList ticketDisclose;
  final bool isEnabled;
  final bool isChange;

  @override
  State<CustomSafetyDisclosurePage> createState() => _CustomSafetyDisclosurePageState();
}

class _CustomSafetyDisclosurePageState extends State<CustomSafetyDisclosurePage> {
  ///安全交底人
  Widget _getSecurityInformantView() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 16.w),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8.w),
      ),
      child: CustomMultiSignaturePage(
        title: '安全交底人：',
        isEnabled: widget.isEnabled,
        isChange: widget.isChange,
        signatureLists: widget.ticketDisclose.discloseUserSign!,
        onCallBack: (value) {
          widget.ticketDisclose.discloseUserSign = value;
        },
      ),
    );
  }

  /// 接受交底人
  Widget _getAcceptTheConfessionView() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 16.w),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8.w),
      ),
      child: Column(
        children: [
          CustomMultiSignaturePage(
            title: '接受交底人：',
            isEnabled: widget.isEnabled,
            isChange: widget.isChange,
            signatureLists: widget.ticketDisclose.discloseUserSign!,
            onCallBack: (value) {
              widget.ticketDisclose.discloseUserSign = value;
            },
          ),
          Divider(
            height: 1.w,
            color: AppColors.bg_color_grey,
          ),
          CustomFileUploadPage(
            title: '文件：',
            isRequired: false,
            isEnabled: widget.isEnabled,
            isChange: widget.isChange,
            uploadedFiles: widget.ticketDisclose.discloseFile!,
            onCallBack: (value) {
              widget.ticketDisclose.discloseFile = value;
            },
          ),
          CustomPickerVideo(
            title: '接受交底记录：',
            videoList: widget.ticketDisclose.discloseVideo == '' ? [] : [widget.ticketDisclose.discloseVideo!],
            maxCount: 1,
            titleTextStyle: TextStyle(
              color: const Color(0xFF262F38),
              fontSize: 14.sp,
              fontWeight: FontWeight.w400,
            ),
            isEnabled: widget.isEnabled,
            isChange: widget.isChange,
            // isEnabled: false,
            callback: (List<String> videos) {
              if (videos.isEmpty) {
                widget.ticketDisclose.discloseVideo = '';
              } else {
                widget.ticketDisclose.discloseVideo = videos[0];
              }
            },
          ),
        ],
      ),
    );
  }

  ///监护人
  Widget _getGuardianView() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 16.w),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8.w),
      ),
      child: Column(
        children: [
          CustomMultiSignaturePage(
            title: '监护人：',
            isEnabled: widget.isEnabled,
            signatureLists: widget.ticketDisclose.discloseUserSign!,
            isChange: widget.isChange,
            onCallBack: (value) {
              widget.ticketDisclose.discloseUserSign = value;
            },
          ),
          Divider(
            height: 1.w,
            color: AppColors.bg_color_grey,
          ),
          CustomFileUploadPage(
            title: '附件：',
            isRequired: false,
            isEnabled: widget.isEnabled,
            isChange: widget.isChange,
            uploadedFiles: widget.ticketDisclose.discloseFile!,
            onCallBack: (value) {
              widget.ticketDisclose.discloseFile = value;
            },
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    //判断交底类型
    switch (widget.ticketDisclose.discloseType) {
      case 0:
        // 安全交底人
        return _getSecurityInformantView();
      case 1:
        // 接受交底人
        return _getAcceptTheConfessionView();
      case 2:
        // 监护人
        return _getGuardianView();
      default:
        return Container();
    }
  }
}
